package com.ohuang.baseapp.view.refresh.OhRefrsh;

import com.ohuang.baseapp.ResourceTable;
import com.ohuang.baseapp.utils.HiLogUtil;
import com.ohuang.baseapp.utils.ToastUtils;
import ohos.agp.components.*;
import ohos.app.Context;

public class TextRefreshView extends ComponentContainer implements RefreshView {
    private Context context;
    private Text text;

    public TextRefreshView(Context context) {
        this(context, null);
    }

    public TextRefreshView(Context context, AttrSet attrSet) {
        super(context, attrSet);
        init(context);
    }

    private void init(Context context) {
        this.context = context;
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_ohrefresh_top_text, null, false);
        text = (Text) component.findComponentById(ResourceTable.Id_text);
        addComponent(component);
    }

    @Override
    public void initRefresh() {
         text.setText("下拉刷新");
    }

    @Override
    public void onRefresh(Refresh refresh) {
       text.setText("正在刷新...");
    }

    @Override
    public void refreshComplete() {
        text.setText("刷新完成");
    }

    @Override
    public void onRelease(Refresh refresh) {
        text.setText("刷新完成");
        context.getUITaskDispatcher().delayDispatch(new Runnable() {
            @Override
            public void run() {
                refresh.refreshComplete();
            }
        },2000);
    }
}
